package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.DialogConfirmBinding
import com.haoshuang.zhouzhoubang.databinding.DialogUpdateVersionBinding
import com.lxj.xpopup.core.CenterPopupView
import com.mufeng.libs.utils.view.clickWithTrigger
import com.mufeng.libs.utils.view.visibleOrGone

/**
 *
 */
class UpdateVersionDialog(
    context: Context,
    private val title: String = "温馨提示",
    private val content: String,
    private val cancelStr: String = "取消",
    private val confirmStr: String = "确认",
    private val isHideCancel: Boolean = false,
    private val isHideAgain: Boolean = false,
    private val onCancel: (isNotAgain: Boolean) -> Unit = {},
    private val onConfirm: () -> Unit = {},
) : CenterPopupView(context) {

    private lateinit var binding: DialogUpdateVersionBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_confirm
    }

    override fun onCreate() {
        super.onCreate()
        binding = DialogUpdateVersionBinding.bind(popupImplView)
        binding.tvTitle.text = title
        binding.tvContent.text = content

        binding.tvCancel.text = cancelStr
        binding.tvCancel.visibleOrGone(!isHideCancel)
        binding.tvConfirm.text = confirmStr

        binding.cbAgain.visibleOrGone(isHideAgain)

        binding.tvCancel.clickWithTrigger {
            dismiss()
            onCancel(binding.cbAgain.isChecked)
        }

        binding.tvConfirm.clickWithTrigger {
            onConfirm()
        }
    }
}